//- 先去这个pug文件中找
extends ../commons/commons.pug

block append pageStyle
	link(href="${relativePath}/static/css/shopping/tjOrder.css" rel="stylesheet" type="text/css")
	link(href="${relativePath}/static/css/shopping/foundation.min.css" rel="stylesheet" type="text/css")
	link(href="${relativePath}/static/css/shopping/foundation-datepicker.css" rel="stylesheet" type="text/css")
	link(href="${relativePath}/static/css/shopping/iconfont.css" rel="stylesheet" type="text/css")
	link(href="${relativePath}/static/css/shopping/fileUpload.css" rel="stylesheet" type="text/css")

block content
	//- 提交订单内容
	div.placeOrderCon.layout
		//- logo部分
		div.submitHeader
			div.logo.fl
				img(src="${relativePath}/static/imgs/shopin.png")

			//- 进度条
			div.orderProcess.fr
				div.processBox
					span.progress1.current
						span.num 1
						br
						span.progressMsg 提交订单
					span.progress1.progress2
						span.num 2
						br
						span.progressMsg 商家接单
					span.progress1.progress3
						span.num 3
						br
						span.progressMsg 支付
					span.progress1.progress4
						span.num 4
						br
						span.progressMsg 完成
		//- 收货地址
		div.receAddress
			h3 选择收货地址

			//- 所有地址列表
			div.addressBox
				ul.addressList
					//- li.current
					//- 	p.name 收货人
					//- 	div.addressTxt
					//- 		p.address 河南省郑州市经开区南三环经开25大街索凌电气
					//- 		p.phone 13332112321

					//- li
					//- 	p.name 收货人
					//- 	div.addressTxt
					//- 		p.address 河南省郑州市经开区南三环经开25大街索凌电气
					//- 		p.phone 13332112321
				p.clickBtn
					a.displayAll(href="javascript:;") 显示全部地址 >
					a.new(href="javascript:;") 使用新地址

			h3 确认商品信息
			//- 确认商品列表
			div.goodsBox
				div.goodsTitle
					ul
						li.spName 商品名称
						li.spMsg 商品信息
						li.unitPrice 单价
						li.number 数量
						li.count 总价
				div.buyList.buyList_c
					div.buyName.fl
						div.imgBox.fl
							img(src="${relativePath}/static/imgs/clList.png")
						div.txtBox.fl
							p 
					//- 商品信息
					ul.msgCon.fl
						//-li 材质：金属拉丝
					//- 单价
					div.djBox.fl
						span.real 385.00
					//- 数量
					div.numberBox.fl 1
					
					//- 总价
					div.allCount.fl.allCount_1 275.00
				//- 交货信息
				div.deverlyDate
					span 交货日期：
					input#timeOne(type="text" placeholder="请选择")
					span.noTime *不含配送时间
					span.zdsj
						| 指定商家：
						i 河南省标识汇有限公司
					span(style="margin-left:40px;") 选择抢单时间：
					select.psTime
						option 1小时
						option 2小时
						option 3小时
						option 4小时
						option 6小时
						option 12小时
						option 24小时
				//- 给供应商留言
				div.leavemsgBox
					p 给供应商留言：
					textarea.txtMsg(name="msg" rows="3" cols="20" placeholder="请输入留言...")

			h3 上传详细信息
			div.upImgBox
				div.upLoad
					input(type="hidden",name="order_img")
					span.up 上传效果图：
					//- span.add
					//- 
					div#fileUploadContent.fileUploadContent.fl
						span.arm *请上传至少一张定制物品的效果图，支持jpg、png、jpeg、bmp格式，单个图片小于4M
						form#uploadForm
							div.z_photo.upimg-div.clear
								section.z_file.fl
									img(src="${relativePath}/static/imgs/addImg.png").add-img
									input(type="file" name="file" id="orderImg" class="file" value="" accept="image/jpg,image/jpeg,image/png,image/bmp" multiple="multiple" )
				div.upLoad.closure
					span.up 上传附件：
					form#fileForm
						span.upImgBtn.fl 上传附件
							input#fileId.file(type="file" name="file" style="float:left")
						span.fileName.fl
					span.arm(style="float:left") *附件为cdr文件，请添加大小不超过5M的cdr文件作为附件
					input.hiddenTxt(type="hidden" name="textHidden" value="")
					
			//- 提交订单		
			div.submitBtn
				div.allMoney.fr
					span 共有1件商品
					span.allCount.allCount_2
						| 共计：
						i ￥
						em 
					span#sub.tjBtn.fr 加入购物车 >

	//- 收货地址模板
	script#address(type="text/html")
		| <li {{if acqu == 1}}class="current"{{/if}} id="{{id}}">
		| 	<p class="name" name="{{accept_name}}">
		|	{{accept_name}}
		|		<a class="fr delete">删除</a>
		|		<a class="fr modify">修改</a>
		|	</p>
		| 	<div class="addressTxt">
		| 		<p class="address" address="{{province_name}}{{city_name}}{{address}}{{area_name}}"> 	{{province_name}}{{city_name}}{{address}}{{area_name}}</p>
		| 		<p class="phone" call="{{mobile}}"> {{mobile}}</p>
		| 	</div>
		| </li>

block append pageScript
	script(type="text/javascript" src="${relativePath}/static/js/libs/iconfont.js")
	script(type="text/javascript" src="${relativePath}/static/js/libs/fileUpload.js")
	script(type="text/javascript" src="${relativePath}/static/js/libs/jquery.form.min.js")

	script.
		//- 规格拼接
		var spec = {};
		var nameArr = decodeURI(thisRequest.specidTxtArr).split(",");
		var valueArr = decodeURI(thisRequest.specidTitleArr).split(",");
		for(var i=0; i<nameArr.length; i++) {
			spec[nameArr[i]] = valueArr[i];
		}

		$.each( spec, function(i, n){
		  	var LiEle = "<li>"+i+ ' ： '+n+"</li>";
		  	$(".msgCon").append(LiEle);
		});

		//- 选择文件
		$("#fileId").on("change",doUpload);
		function doUpload(argument) {
			var file = this.files[0];
			var formdata=new FormData($("#fileForm")[0]);
			//console.log(formdata);
			$.ajax({
				url:shopIp+"/Utils/uploadFiles?userToken="+token,
				type:"post",
				data:formdata,
				dataType:"json",
				async:false,
				cache:false,
				contentType:false,
				processData:false,
				success:function(data) {
					//alert(data.msg);
					//console.log(data.data.path);
					if(data.status == 200) {
						$(".hiddenTxt").val(data.data.path);
					}else{
						layer.msg(data.msg);
					}
					
				},
				error:function(data) {
					layer.msg(data.msg);
				}
			})
			$(".fileName").html($(".hiddenTxt").val());
		}
		//- 图片上传
		$("input#orderImg").on("change", function() {
			var wrap = $(this).closest(".upimg-div");
			doUpload_img(this.files[0], function(data) {
				var imgUrl = $("input[name='order_img']").val();
				if(imgUrl) {
					$("input[name='order_img']").val(imgUrl + "," + data.data.path);
				} else {
					$("input[name='order_img']").val(data.data.path);
				}
				wrap.prepend("<span class='imgwarp'><img src='"+data.data.url+"' class='upimgs' path='"+data.data.path+"'></img><i></i></span>");
				if($("span.imgwarp img.upimgs").length > 4) {
					$("#orderImg").hide();
					$(".add-img").hide();
				}
				
			});
		});
		//- 上传图片
		function doUpload_img(file, callback) {
			var formdata=new FormData($("#uploadForm")[0])
			//console.log(formdata);
			$.ajax({
				url:shopIp+"/Utils/uploadFiles?userToken="+token,
				type:"post",
				data:formdata,
				dataType:"json",
				async:false,
				cache:false,
				contentType:false,
				processData:false,
				success:function(data) {
					//alert(data.msg);
					//$(".hiddenTxt").val(data.data.path);
					callback(data);
				},
				error:function(data) {
					layer.msg(data.msg);
				}
			})
		}
		//- 点击删除图片
		$(".z_photo").on("click",".imgwarp i",function() {
			$(this).closest(".imgwarp").remove();
			$("#orderImg").show();
			$(".add-img").show();
		})

		//console.log(spec);
		$(function(){
			//- 选择收货日期
			$('#timeOne').fdatepicker({
				format: 'yyyy-mm-dd',
				onRender: function (date) {
					var nowTemp = new Date();
					var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
					return date.valueOf() < now.valueOf() ? 'disabled' : '';
				}
			});

			//- 点击收货地址
			$(".addressList").on("click","li",function(){
				$(this).addClass("current").siblings().removeClass("current");
			});
			//- 收货地址列表
			$.getJSON(shopIp+"/Address/lst?callback=?",{
				userToken:token,
				os:"web",
			},function(data){
				console.log(data);
				if(data.data.length > 4){
					$(".displayAll").show();
				}
				if(data.status == "200"){
					for(var i=0;i<data.data.length;i++) {
						var addressHtml = template("address",data.data[i]);
						$(".addressList").append(addressHtml);
					}
				}else{
					$(".addressList").append('<div class="addAddress">'+"请添加收货地址"+'</div>');
				}
			})


			//- 确认商品信息
			var sizeArr = thisRequest.size.split("x");
			$(".imgBox img").attr("src",thisRequest.src);
			$(".txtBox p").html(decodeURI(thisRequest.title));
			$(".real").html(thisRequest.price);
			$(".numberBox").html(thisRequest.number+decodeURI(sizeArr[3]));
			$(".zdsj i").html(decodeURI(thisRequest.ghs));
			$(".allCount_1").html((thisRequest.number)*(thisRequest.price));
			$(".allCount_2 em").html((thisRequest.number)*(thisRequest.price));

			//- 供应商
			var gysList = decodeURI(thisRequest.companies);
			$(".zdsj i").html(gysList);

			//- 供应商id
			var Ids = thisRequest.companyIds;

			//- 点击提交
			$("#sub").click(function() {
				var str = $(".psTime").val();
				//console.log(str.slice(0,-2));
				var name = $("li.current .name").attr("name");
				var call = $("li.current .phone").attr("call");
				var address = $("li.current .address").attr("address");
				//- 效果图
				var imgsArr = [];
				$(".z_photo img").not(".add-img").each(function(){
					imgsArr.push($(this).attr("path"));
				})
				if($("#timeOne").val() == ""){
					layer.msg("请选择交货时间!");
				}else{
					$.ajax({
						url:shopIp+"/My/addCart",
						type:"post",
						data:{
							userToken:token,
							sku_id:thisRequest.sku_id,
							seller_ids:Ids,
							reciver_name:name,
							reciver_mobile:call,
							reciver_address:address,
							order_amount:thisRequest.price,
							goods_num: thisRequest.number,
							goods_width:decodeURI(sizeArr[3]),
							goods_height : sizeArr[1], 
							goods_thick : sizeArr[2],
							expiry_time:Number(str.slice(0,-2)) *3600,
							order_files:$(".hiddenTxt").val(),
							order_img:imgsArr,
							deliver_time:new Date($("#timeOne").val()).getTime()/1000,
							member_explain:$(".txtMsg").val(),
						},
						dataType: "json",
					}).done(function(data){
						//console.log(data);
						if(data.status == 200){
							var order_id = data.data.order_id;
							$(".gwCar i").html(data.data.cart_number);
							window.location.href = "../personCenter/shopCar.html";
						}else{
							layer.msg(data.msg);
						}
					})
				}
				
			});

			//- 点击修改地址
			$(".addressList").on("click",".modify",function() {
				window.location.href="../personCenter/receveAddress.html";
			})
			//- 点击删除地址
			$(".addressList").on("click",".delete",function() {
				var $this = $(this);
				layer.confirm('您确定删除此收货地址？', {
					btn: ['确定','取消'],//按钮
					title:"删除收货地址"
				}, function(){
					$.post(shopIp+"/Address/delAccept",{
						userToken:token,
						id:$this.closest("li").attr("id"),
					},function(data) {
						//console.log(data.msg);
						if(data.status == "200") {
							layer.msg(data.msg, {icon: 1});
							$this.closest("li").remove();
							setTimeout(function() {
								location.reload();
							},1000);
						} else{
							layer.msg(data.msg);
						}
					})
				}, function(){
						//layer.msg('已取消');
				});
			})

			//- 点击查看全部地址
			$(".displayAll").click(function() {
				if($(this).text() == "显示全部地址 >") {
					$(".addressList").css("height","auto");
					$(this).html("隐藏收货地址 >");
				} else{
					$(".addressList").css("height","165px");
					$(this).html("显示全部地址 >");
				}
				
			})

		});


		